#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 连接信号槽，通过槽函数更新界面
    connect(&thread, &Thread::notify, this, &Widget::handle);

    thread.start();

    // mutex
    Thread t1;
    Thread t2;
    t1.start();
    t2.start();

    // 主线程等待这两个线程执行结束
    t1.wait();
    t2.wait();

    qDebug() << Thread::num;

}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    int value = ui->lcdNumber->intValue();
    value--;
    ui->lcdNumber->display(value);
}

